package com.jacquesh;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * union Demo
 * DataStream * → DataStream
 * 合并两个或者更多的数据流产生一个新的数据流，这个新的数据流中包含了所合并的数据流的元素
 * 注意：需要保证数据流中元素类型一致
 */
public class FlinkDemo0006 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment environment =
                StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<String> stream1 = environment
                .socketTextStream("192.168.88.180", 8888);
        DataStreamSource<String> stream2 = environment
                .socketTextStream("192.168.88.181", 8888);
        stream1.union(stream2).print();
        environment.execute("union demo");
    }
}
